
var setting = {
    check: {
        enable: true,
        chkStyle: "checkbox",
        chkboxType: { "Y" : "ps", "N" : "ps" }
    },

    data: {
        key: {
            name: "authorityName"
        },
        simpleData: {
            enable: true,
            idKey: "authorityId",
            pIdKey: "authorityParentId",
            rootPId: "0"
        }
    },
    callback: {
        onCheck: checkBaseNode
    }
};

// var zNodes =[
//     { id:1, pId:0, name:"标签管理",bId:0, open:true},
//     { id:15, pId:1, name:"查看标签",bId:0,checked:true},
//     { id:13, pId:1, name:"增加标签",bId:15},
//     { id:14, pId:1, name:"修改标签",bId:15},
//     { id:12, pId:1, name:"删除标签",bId:15}
// ];


function checkBaseNode(e,treeId,treeNode){
    var treeObj = $.fn.zTree.getZTreeObj("tree");
    var baseNode = getBaseNode(treeNode);
    //如果当前节点有base节点，并且，当前节点被选中
    if(treeNode.authorityBaseId!=0 && treeNode.checked == true){
        //alert();
        // baseNode[0].chcked=true;
        //设置baseNode为选中
        treeObj.checkNode(baseNode, true, true,true);
        //禁用base节点的编辑
        treeObj.setChkDisabled(baseNode, true);
    }
    if(treeNode.authorityBaseId!=0 && treeNode.checked == false){
        //获取所有基于 当前节点的base节点 的节点
        //举例，增删改基于查，则 若当前节点为增节点，则获得 增删改节点
        var nodes = treeObj.getNodesByParam("authorityBaseId", baseNode.authorityId, null);
        var haveChecked = false;
        for(var i = 0; i<nodes.length;i++){
            if(nodes[i].checked == true){
                haveChecked = true;
                break;
            }
        }
        //若没用被选中的节点了，则使base节点可编辑
        if(haveChecked ==false){
            treeObj.setChkDisabled(baseNode, false);
        }

    }
    //全选按钮被选中时
    //alert(treeNode.pId+""+treeNode.name+"");
    if(treeNode.isParent && treeNode.checked == true){
        var nodes = treeNode.children;
        for(var i = 0; i<nodes.length;i++){
            //如果为base节点
            if(nodes[i].authorityBaseId == 0){
                //设置禁用状态
                treeObj.setChkDisabled(nodes[i], true);
            }
        }
    }
    //全选按钮被取消时
    if(treeNode.isParent && treeNode.checked == false){
        var nodes = treeNode.children;
        for(var i = 0; i<nodes.length;i++){
            if(nodes[i].authorityBaseId == 0){
                treeObj.setChkDisabled(nodes[i], false);
                treeObj.checkNode(nodes[i], false, true);
            }
        }
    }
}
function getBaseNode(treeNode){
    var treeObj = $.fn.zTree.getZTreeObj("tree");
    var baseNode = treeObj.getNodesByParam("authorityId", treeNode.authorityBaseId, null);
    return baseNode[0];
}
//-->